#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
//http://oj33.cn/contest.php?cid=1075
//https://blog.csdn.net/qq_37482202/article/details/89513877
int fa[55];
long long int ans;
struct node
{
	int u, v, w;
}M[55];
int g[55][55];
bool com(node a, node b)
{
	return a.w < b.w;
}
int find(int x)
{
	if (x == fa[x])return x;
	return fa[x] = find(fa[x]);
}
int main()
{
	for (int i = 1; i <= 54; i++)fa[i] = i;
	int n;
	cin >> n;
	int k = 1;
	int a;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			cin >> a;
			if (a != 0 && j > i) {
				M[k].w = a;
				M[k].u = i;
				M[k].v = j;
				k++;
			}

		}
	}
	int num = 0;
	sort(M + 1, M  + k, com);
		for (int i = 1; i <= k; i++)
		{
			int fx = find(M[i].u);
			int fy = find(M[i].v);
			if (fx != fy)
			{
				num++;
				fa[fx] = fy;
				ans += M[i].w;
			}
			if (num + 1 == n)
			{
				cout << ans << endl;
			}
		}
		
	return 0;
}